package com.smartHome.controller;

import com.smartHome.pojo.entity.Result;
import com.smartHome.pojo.entity.Room;
import com.smartHome.pojo.vo.RoomVO;
import com.smartHome.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@RestController
@RequestMapping("/room")
public class RoomController {

    @Autowired
    private RoomService roomService;

    @PostMapping("/addRoom")
    public Result add(@RequestBody Room room) {
        roomService.add(room);
        return Result.success();
    }

    @GetMapping("/{houseId}")
    public Result<List<RoomVO>> roomInfo(@PathVariable Integer houseId) {
        List<RoomVO> roomList = roomService.getByHouseId(houseId);
        return Result.success(roomList);
    }

    /**
     * 删除房间
     * @param roomId
     */
    @GetMapping("/delete/{roomId}")
    public Result<List<RoomVO>> deleteRoom(@PathVariable Integer roomId) {
        roomService.deleteRoomById(roomId);
        return Result.success();
    }

    /**
     * 获取屋子ID
     * @param roomId
     * @return
     */
    @GetMapping("/getHouseId/{roomId}")
    public Result<Integer> getHouseId(@PathVariable Integer roomId) {
        Integer houseId=roomService.getHouseId(roomId);
        return Result.success(houseId);
    }
}
